1 /* JJT: 0.2.2 */ 2 3 package mobisnap.mobile_trx; 4 5 import java.util.*; 6 7 /*** 8 * Implements simple expression 9 */ 10 public class ASTSQLSimpleExpression extends mobisnap.mobile_trx.SimpleNode { 11 public static final byte OP_PLUS = 0; 12 public static final byte OP_MINUS = 1; 13 public static final byte OP_OR = 2; 14 15 public SimpleNode first; 16 public Vector ors; 17 18 public ASTSQLSimpleExpression(int id) { 19 super(id); 20 ors = new Vector(); 21 } 22 23 public ASTSQLSimpleExpression( MobisnapSQL p, int i) { 24 super( p, i); 25 id = i; 26 ors = new Vector(); 27 } 28 29 /*** Accept the visitor. **/ 30 public Object jjtAccept(MobisnapSQLVisitor visitor, Object data) { 31 return visitor.visit(this, data); 32 } 33 34 public class term { 35 public byte opType; 36 public SimpleNode expr; 37 38 public term( byte opType, ASTSQLMultiplicativeExpression expr) { 39 this.opType = opType; 40 this.expr = expr; 41 } 42 }; 43 44 public void insert( byte opType, ASTSQLMultiplicativeExpression expr) { 45 ors.addElement( new term( opType, expr)); 46 } 47 48 /*** 49 * Returns the value of the expression 50 * 51 * @param msql_type Specifies which type of processing should be performed 52 * MobisnapConstants.MSQL_SERVER = 1 53 * MobisnapConstants.MSQL_TENTATIVE_CLIENT = 2 54 * MobisnapConstants.MSQL_STABLE_CLIENT = 3 55 * MobisnapConstants.MSQL_RESERVATION_CLIENT = 4 56 * MobisnapConstants.MSQL_STATIC = 10 57 * @param cond True if reservations associated iwth transaction should be 58 * propagated to the current transaction 59 */ 60 public Object value( int msql_type, boolean cond) throws Exception { 61 Object val = first.value( msql_type, cond); 62 for( int i = 0; i < ors.size(); i++) { 63 term t = (term)ors.elementAt( i); 64 if( t.opType == OP_PLUS) 65 val = MSQLTypeUtil.add( val, t.expr.value( msql_type, cond)); 66 else if( t.opType == OP_MINUS) 67 val = MSQLTypeUtil.subtract( val, t.expr.value( msql_type, cond)); 68 else 69 val = MSQLTypeUtil.concat( val, t.expr.value( msql_type, cond)); 70 } 71 return val; 72 } 73 74 /*** 75 * Returns a simplified node, if possible (usefull in expressions) 76 * 77 * @param msql_type Specifies which type of processing should be performed 78 * MobisnapConstants.MSQL_SERVER = 1 79 * MobisnapConstants.MSQL_TENTATIVE_CLIENT = 2 80 * MobisnapConstants.MSQL_STABLE_CLIENT = 3 81 * MobisnapConstants.MSQL_RESERVATION_CLIENT = 4 82 * MobisnapConstants.MSQL_STATIC = 10 83 * @param cond True if reservations associated iwth transaction should be 84 * propagated to the current transaction 85 */ 86 public SimpleNode simplify( int msql_type, boolean cond) { 87 first = (SimpleNode)first.simplify( msql_type, cond); 88 for( int i = 0; i < ors.size(); i++) { 89 term t = (term)ors.elementAt( i); 90 t.expr = t.expr.simplify( msql_type, cond); 91 } 92 if( ors.size() == 0) 93 return first; 94 try { 95 return new SimpleNodeValue( value( msql_type, cond)); 96 } catch( Exception e) { 97 return this; 98 } 99 } 100 101 }

This page was automatically generated by Maven